package com.cheyunkeji.er.activity.evaluate;

import android.content.ClipboardManager;
import android.content.Intent;
import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;

import com.cheyun.netsalev3.R;
import com.cheyunkeji.er.Constants;
import com.cheyun.netsalev3.MyApplication;
import com.cheyunkeji.er.base.BaseActivity;
import com.cheyunkeji.er.bean.evaluate.BeforeArchiveListItem;
import com.cheyunkeji.er.bean.evaluate.CarArchive;
import com.cheyunkeji.er.bean.evaluate.CarArchiveDetail;
import com.cheyunkeji.er.bean.evaluate.CarBaseInfoData;
import com.cheyunkeji.er.bean.evaluate.CarBaseInfoIds;
import com.cheyunkeji.er.bean.evaluate.CarInfo;
import com.cheyunkeji.er.bean.evaluate.CarInfoSearchedByVin;
import com.cheyunkeji.er.bean.evaluate.CustomerArchiveInfo;
import com.cheyunkeji.er.http.ApiClient;
import com.cheyunkeji.er.http.HttpConstants;
import com.cheyunkeji.er.http.RespCallback;
import com.cheyunkeji.er.utils.ChannelInfoUtil;
import com.cheyunkeji.er.utils.InputLowerToUpper;
import com.cheyunkeji.er.utils.TimeUtils;
import com.cheyunkeji.er.view.DatePickerUtil;
import com.cheyunkeji.er.view.SDialog;
import com.cheyunkeji.er.view.SToast;
import com.cheyunkeji.er.view.TabTitle;
import com.cheyunkeji.er.view.TopBar;
import com.cheyunkeji.er.view.evaluate.wheel_selector.IListPickerOK;
import com.cheyunkeji.er.view.evaluate.wheel_selector.InfoData;
import com.cheyunkeji.er.view.evaluate.wheel_selector.ListPicker;
import com.cheyunkeji.er.view.evaluate.wheel_selector.PickData;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.zhy.http.okhttp.callback.StringCallback;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.Serializable;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import cn.qqtheme.framework.picker.DatePicker;
import okhttp3.Call;
import okhttp3.Request;

public class AddCarArchiveActivity extends BaseActivity implements IListPickerOK, DatePicker.OnYearMonthDayPickListener, SDialog.SDialog2Listener {

    private static final String TAG = AddCarArchiveActivity.class.getSimpleName();

    private static final int SELECT_OWNER_ARCHIVE_REQUEST_CODE = 0x10;
    private static final int SELECT_CAR_BY_VIN_REQUEST_CODE = 0x11;

    private static final int OPERATION_MODE_ADD_NEW_ARCHIVE_INFO = 1;
    private static final int OPERATION_MODE_UPDATE_ARCHIVE_INFO = 2;

    private static final int REQUEST_CODE_SELECT_CAR_BRAND = 0x124;
    private static final int REQUEST_CODE_SELECT_CAR_SERIES = 0x125;
    private static final int REQUEST_CODE_SELECT_CAR_MODEL = 0x126;

    //    操作模式 ： 添加新的车辆档案/修改已有车辆档案
    private static int CURRENT_OPERATION_MODE = OPERATION_MODE_UPDATE_ARCHIVE_INFO;
    @BindView(R.id.v_topbar)
    TopBar vTopbar;
    @BindView(R.id.tv_vin_code)
    TextView tvVinCode;
    @BindView(R.id.tv_query_vin)
    TextView tvQueryVin;
    @BindView(R.id.tv_copy_vin)
    Button tv_copy_vin;
    @BindView(R.id.tv_plate_number)
    TextView tvPlateNumber;
    @BindView(R.id.et_palate_number)
    EditText etPlateNumber;
    @BindView(R.id.tv_engine_number)
    TextView tvEngineNumber;
    @BindView(R.id.et_engine_number)
    EditText etEngineNumber;
    @BindView(R.id.tt_carinfo)
    TabTitle ttCarinfo;
    @BindView(R.id.ll_car_model_tip)
    LinearLayout ll_car_model_tip;
    @BindView(R.id.tv_car_model_vv)
    TextView tv_car_model_vv;
    @BindView(R.id.tv_car_brand)
    TextView tvCarBrand;
    @BindView(R.id.ll_car_brand)
    LinearLayout llCarBrand;
    @BindView(R.id.tv_car_series)
    TextView tvCarSeries;
    @BindView(R.id.ll_car_series)
    LinearLayout llCarSeries;
    @BindView(R.id.tv_car_model)
    TextView tvCarModel;
    @BindView(R.id.ll_car_model)
    LinearLayout llCarModel;
    @BindView(R.id.tv_car_age)
    TextView tvCarAge;
    @BindView(R.id.ll_car_age)
    LinearLayout llCarAge;
    @BindView(R.id.tv_car_style)
    TextView tvCarStyle;
    @BindView(R.id.ll_car_style)
    LinearLayout llCarStyle;
    @BindView(R.id.tv_car_bsx)
    TextView tvCarBsx;
    @BindView(R.id.ll_car_bsx)
    LinearLayout llCarBsx;
    @BindView(R.id.tv_car_pfbz)
    TextView tvCarPfbz;
    @BindView(R.id.ll_car_pfbz)
    LinearLayout llCarPfbz;
    @BindView(R.id.tv_car_pl)
    TextView tvCarPl;
    @BindView(R.id.ll_car_pl)
    LinearLayout llCarPl;
    @BindView(R.id.tv_car_rllx)
    TextView tvCarRllx;
    @BindView(R.id.ll_car_rllx)
    LinearLayout llCarRllx;
    @BindView(R.id.tv_car_qdfs)
    TextView tvCarQdfs;
    @BindView(R.id.ll_car_qdfs)
    LinearLayout llCarQdfs;
    @BindView(R.id.tv_car_gs)
    TextView tvCarGs;
    @BindView(R.id.ll_car_gs)
    LinearLayout llCarGs;
    @BindView(R.id.tv_car_zws)
    TextView tvCarZws;
    @BindView(R.id.ll_car_zws)
    LinearLayout llCarZws;
    @BindView(R.id.ll_car_info)
    LinearLayout llCarInfo;
    @BindView(R.id.tt_user_info)
    TabTitle ttUserInfo;
    @BindView(R.id.tv_user_name)
    TextView tvUserName;
    @BindView(R.id.tv_query_username)
    TextView tvQueryUsername;
    @BindView(R.id.et_user_telenumber)
    TextView etUserTelenumber;
    @BindView(R.id.ll_user_telenumber)
    LinearLayout llUserTelenumber;
    @BindView(R.id.tv_user_category)
    TextView tvUserCategory;
    @BindView(R.id.ll_user_category)
    LinearLayout llUserCategory;
    @BindView(R.id.tv_user_gender)
    TextView tvUserGender;
    @BindView(R.id.ll_user_gender)
    LinearLayout llUserGender;
    @BindView(R.id.et_user_address)
    TextView etUserAddress;
    @BindView(R.id.ll_user_address)
    LinearLayout llUserAddress;
    @BindView(R.id.ll_user_info)
    LinearLayout llUserInfo;
    @BindView(R.id.sv_content)
    ScrollView svContent;
    @BindView(R.id.activity_add_car_archive)
    RelativeLayout activityAddCarArchive;
    @BindView(R.id.tv_save)
    TextView tvSave;
    @BindView(R.id.et_vin)
    EditText etVin;
    @BindView(R.id.et_pl_number)
    EditText etPlNumber;
    @BindView(R.id.et_user_name)
    EditText etUserName;
    @BindView(R.id.ll_car_plunit)
    LinearLayout llCarPlunit;
    @BindView(R.id.tv_chuchang_date)
    TextView tvChuchangDate;
    @BindView(R.id.iv_chuchang)
    ImageView ivChuchang;
    @BindView(R.id.tv_shangpai_date)
    TextView tvShangpaiDate;
    @BindView(R.id.iv_shangpai)
    ImageView ivShangpai;
    @BindView(R.id.tv_door_count)
    TextView tvDoorCount;
    @BindView(R.id.ll_door_count)
    LinearLayout llDoorCount;
    @BindView(R.id.tv_vehicle_manufactory)
    TextView tvVehicleManufactory;
    @BindView(R.id.ll_vehicle_manufactory)
    LinearLayout llVehicleManufactory;
    //    保存车辆信息的HashMap
    private HashMap<String, String> carInfoMap = new HashMap<>();
    private ArrayList<PickData> dataList;
    //    列表滚动选择器
    private ListPicker listPicker;

    private Calendar calendar;

    //    当前选中车辆品牌
    private CarInfo.CarBrand selectedCarBrand;
    //    当前选中车型
    private CarInfo.CarModel selectedCarModel;
    //    当前选中车系
    private CarInfo.CarSeries selectedCarSeries;

    // 客户信息
    private CustomerArchiveInfo carOwnerArchiveInfo = null;

    //   当前页面车辆档案详情信息（从车辆档案列表传来）
    private CarArchiveDetail carArchiveDetail;

    //    VIN搜索获取到的车辆信息
    private CarInfoSearchedByVin carInfoReturnedByVinSearch;
    private CarInfo.CarManufactory selectedManufactory;

    private SDialog singleDialog;

    private String mode_mark;

    @Override
    protected void init() {
        setContentView(R.layout.er_activity_add_car_archive);
        ButterKnife.bind(this);

        dataList = new ArrayList<>();
        calendar = Calendar.getInstance();
    }

    @Override
    protected void initView() {
        vTopbar.setTitle("新增车辆档案");
        vTopbar.setRight("保存", 0, this);
        vTopbar.setLeftBack();

        ttCarinfo.setView(llCarInfo, svContent);
        ttUserInfo.setView(llUserInfo, svContent);

        ttUserInfo.hideIndicator();
        ttCarinfo.hideIndicator();

        ttUserInfo.setTitle("客户信息");
        ttCarinfo.setTitle("车辆信息");

//      设置VIN输入框小写自动转换大写
        etVin.setTransformationMethod(InputLowerToUpper.getInstance());

        initListener();

        listPicker = new ListPicker(this, this, activityAddCarArchive);

        if (getIntent().hasExtra("waitData")) {
            BeforeArchiveListItem beforeArchiveListItem = (BeforeArchiveListItem)getIntent().getSerializableExtra("waitData");
            etVin.setText(beforeArchiveListItem.getVin());
            etPlateNumber.setText(beforeArchiveListItem.getPlate());
            etUserName.setText(beforeArchiveListItem.getOwner_realname());
            etUserTelenumber.setText(beforeArchiveListItem.getOwner_phone());
        }
    }

    @Override
    protected void initData() {
        if (null != getIntent().getSerializableExtra("CAR_ARCHIVE")) {
            displayCarInfo((CarArchive) getIntent().getSerializableExtra("CAR_ARCHIVE"));
//           有车辆档案数据传入，档案操作则为编辑修改模式，否则为新建车辆档案
            CURRENT_OPERATION_MODE = OPERATION_MODE_UPDATE_ARCHIVE_INFO;
        } else {
            CURRENT_OPERATION_MODE = OPERATION_MODE_ADD_NEW_ARCHIVE_INFO;
            if (!TextUtils.isEmpty(getIntent().getStringExtra("VIN"))) {
                etVin.setText(getIntent().getStringExtra("VIN"));
            }
        }
    }


    //    车辆档案详情页--可修改车辆信息
    private void displayCarInfo(CarArchive carArchive) {
        vTopbar.setTitle("车辆档案详情");
        etVin.setText(carArchive.getVin());
        etPlateNumber.setText(carArchive.getPlate());

        if (ChannelInfoUtil.getCurrentChannelInfo().getIsadmin() == 1) {
            tvQueryVin.setText("更新");
            etVin.setEnabled(true);
        } else {
            tvQueryVin.setVisibility(View.GONE);
            etVin.setEnabled(false);
            etVin.setFocusableInTouchMode(false);

            tv_copy_vin.setVisibility(View.VISIBLE);
        }
        if (!TextUtils.isEmpty(carArchive.getVid())) {
            loadCarArchiveDetailInfo(carArchive.getVid());
            carInfoMap.put("vid", carArchive.getVid());
        }
    }

    /**
     * 获取车辆档案详细信息
     *
     * @param vid 车辆档案vid
     */
    private void loadCarArchiveDetailInfo(String vid) {
        HashMap<String, String> params = new HashMap<>();
//        params.put("authkey", UserInfoManager.getInstance(MyApplication.getInstance()).getAuthKey());
//        params.put(ChannelInfoUtil.getCurrentChannelInfo().getCkey1().getYkey(), ChannelInfoUtil.getCurrentChannelInfo().getCkey1().getY7e_e73a691f02a46500201c3998e6a2989d());
        params.put("vid", vid);
        Log.e(TAG, "loadCarArchiveDetailInfo:  vid : " + vid);
        ApiClient.get(HttpConstants.GET_OR_UPDATE_CAR_ARCHIVE, params, new RespCallback<CarArchiveDetail>() {

            @Override
            protected void onRequestFailed(String msg) {
                SToast.show(msg);
            }

            @Override
            protected void onSuccess(CarArchiveDetail data) {
                Log.e(TAG, "onSuccess: " + new Gson().toJson(data));
                carArchiveDetail = data;
                fillCarArchiveInfo(data);
            }

            @Override
            public void onBefore(Request request, int id) {
                super.onBefore(request, id);
                showDialog();
            }

            @Override
            public void onAfter(int id) {
                super.onAfter(id);
                dismissDialog();
            }
        });

    }


    //    回填车辆档案信息
    private void fillCarArchiveInfo(CarArchiveDetail data) {
        if (!TextUtils.isEmpty(data.getVehicle_info().getVin()))
            carInfoMap.put("vin", data.getVehicle_info().getVin());

        if (isValidFormat(data.getVehicle_info().getBrand())) {
            tvCarBrand.setText(data.getVehicle_info().getBrand().split(",")[0]);
            carInfoMap.put("brand", data.getVehicle_info().getBrand().split(",")[1]);
            if (selectedCarBrand == null)
                selectedCarBrand = new CarInfo.CarBrand(data.getVehicle_info().getBrand().split(",")[1], data.getVehicle_info().getBrand().split(",")[0], "");
        }

        if (isValidFormat(data.getVehicle_info().getSeries())) {
            tvCarSeries.setText(data.getVehicle_info().getSeries().split(",")[0]);
            carInfoMap.put("series", data.getVehicle_info().getSeries().split(",")[1]);
            if (selectedCarSeries == null) {
                selectedCarSeries = new CarInfo.CarSeries(data.getVehicle_info().getSeries().split(",")[1], data.getVehicle_info().getSeries().split(",")[0]);
            }
        }

        if (isValidFormat(data.getVehicle_info().getSpec())) {
            tvCarModel.setText(data.getVehicle_info().getSpec().split(",")[0]);
            carInfoMap.put("spec", data.getVehicle_info().getSpec().split(",")[1]);
            if (selectedCarModel == null) {
                selectedCarModel = new CarInfo.CarModel(data.getVehicle_info().getSpec().split(",")[1], data.getVehicle_info().getSpec().split(",")[0]);
            }
        }

        if (isValidFormat(data.getVehicle_info().getCyear())) {
            tvCarAge.setText(data.getVehicle_info().getCyear().split(",")[0]);
            carInfoMap.put("cyear", data.getVehicle_info().getCyear().split(",")[1]);
        }

        if (isValidFormat(data.getVehicle_info().getBodystyle())) {
            tvCarStyle.setText(data.getVehicle_info().getBodystyle().split(",")[0]);
            carInfoMap.put("bodystyle", data.getVehicle_info().getBodystyle().split(",")[1]);
        }

        if (isValidFormat(data.getVehicle_info().getTrans())) {
            tvCarBsx.setText(data.getVehicle_info().getTrans().split(",")[0]);
            carInfoMap.put("trans", data.getVehicle_info().getTrans().split(",")[1]);
        }

        if (isValidFormat(data.getVehicle_info().getEmission())) {
            tvCarPfbz.setText(data.getVehicle_info().getEmission().split(",")[0]);
            carInfoMap.put("emission", data.getVehicle_info().getEmission().split(",")[1]);
        }

        if (!TextUtils.isEmpty(data.getVehicle_info().getDispunit())) {
            tvCarPl.setText(data.getVehicle_info().getDispunit());
            carInfoMap.put("dispunit", data.getVehicle_info().getDispunit());
        }

        if (isValidFormat(data.getVehicle_info().getFueltype())) {
            tvCarRllx.setText(data.getVehicle_info().getFueltype().split(",")[0]);
            carInfoMap.put("fueltype", data.getVehicle_info().getFueltype().split(",")[1]);
        }

        if (isValidFormat(data.getVehicle_info().getDrivetrain())) {
            tvCarQdfs.setText(data.getVehicle_info().getDrivetrain().split(",")[0]);
            carInfoMap.put("drivetrain", data.getVehicle_info().getDrivetrain().split(",")[1]);
        }

        if (isValidFormat(data.getVehicle_info().getCylinders())) {
            tvCarGs.setText(data.getVehicle_info().getCylinders().split(",")[0]);
            carInfoMap.put("cylinders", data.getVehicle_info().getCylinders().split(",")[1]);
        }

        if (isValidFormat(data.getVehicle_info().getSeats())) {
            tvCarZws.setText(data.getVehicle_info().getSeats().split(",")[0]);
            carInfoMap.put("seats", data.getVehicle_info().getSeats().split(",")[1]);
        }

        if (isValidFormat(data.getVehicle_info().getDoor())) {
            tvDoorCount.setText(data.getVehicle_info().getDoor().split(",")[0]);
            carInfoMap.put("door", data.getVehicle_info().getDoor().split(",")[1]);
        }

        if (isValidFormat(data.getVehicle_info().getFacturer())) {
            tvVehicleManufactory.setText(data.getVehicle_info().getFacturer().split(",")[0]);
            carInfoMap.put("facturer", data.getVehicle_info().getFacturer().split(",")[1]);
        }

        carInfoMap.put("ownercid", data.getVehicle_info().getOwnercid());

        etEngineNumber.setText(data.getVehicle_info().getEngineno());

        if (!TextUtils.isEmpty(data.getVehicle_info().getDisplace())) {
            etPlNumber.setText(data.getVehicle_info().getDisplace());
            carInfoMap.put("displace", data.getVehicle_info().getDisplace());
        }

        etUserName.setText(data.getVehicle_info().getRealname());
        etUserTelenumber.setText(data.getVehicle_info().getPhone());
        etUserAddress.setText(data.getVehicle_info().getAddress());

        if (!TextUtils.isEmpty(data.getVehicle_info().getExwdate()))
            tvChuchangDate.setText(TimeUtils.millis10bitToStringWithoutHMS(data.getVehicle_info().getExwdate()));
        if (!TextUtils.isEmpty(data.getVehicle_info().getLicdate()))
            tvShangpaiDate.setText(TimeUtils.millis10bitToStringWithoutHMS(data.getVehicle_info().getLicdate()));

        tvUserGender.setText(data.getVehicle_info().getSex().equals("1") ? "男" : data.getVehicle_info().getSex().equals("2") ? "女" : "未知");
        tvUserCategory.setText(data.getVehicle_info().getCategory().equals("1") ? "个人" :
                data.getVehicle_info().getCategory().equals("2") ? "公司" : data.getVehicle_info().getCategory().equals("3") ? "行政单位" : "未知");
    }


    /**
     * 分割字符串后获取的数据是否有效
     *
     * @param field
     * @return
     */
    private boolean isValidFormat(String field) {
        return !TextUtils.isEmpty(field) && field.split(",").length == 2 && !TextUtils.equals(field.split(",")[1], "0");
    }


    private void initListener() {
        llCarBrand.setOnClickListener(this);
        llCarSeries.setOnClickListener(this);
        llCarModel.setOnClickListener(this);
        llCarAge.setOnClickListener(this);
        llCarStyle.setOnClickListener(this);
        llCarBsx.setOnClickListener(this);
        llCarPfbz.setOnClickListener(this);
        llCarPlunit.setOnClickListener(this);
        llCarRllx.setOnClickListener(this);
        llCarQdfs.setOnClickListener(this);
        llCarGs.setOnClickListener(this);
        llCarZws.setOnClickListener(this);
        llDoorCount.setOnClickListener(this);
        llVehicleManufactory.setOnClickListener(this);
        tvQueryUsername.setOnClickListener(this);
        tvQueryVin.setOnClickListener(this);
        tv_copy_vin.setOnClickListener(this);
        tvSave.setOnClickListener(this);
        ivChuchang.setOnClickListener(this);
        ivShangpai.setOnClickListener(this);

        ivShangpai.setOnClickListener(this);
        ivChuchang.setOnClickListener(this);
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.ll_car_brand:
                Intent intent = new Intent(this, SelectCarInfoActivity.class);
                intent.putExtra(Constants.CAR_BRAND_LEVEL_BRAND, 1);
                intent.putExtra("Mark",mode_mark);
                startActivityForResult(intent, REQUEST_CODE_SELECT_CAR_BRAND);
                break;
            case R.id.ll_car_series:
                if (selectedCarBrand == null) {
                    SToast.show("请选择车辆品牌");
                    return;
                }
                Intent intent2 = new Intent(this, SelectCarInfoActivity.class);
                intent2.putExtra(Constants.CAR_BRAND_LEVEL_BRAND, 2);
                intent2.putExtra("pid", selectedCarBrand.getId());
                intent2.putExtra("Mark",mode_mark);
                startActivityForResult(intent2, REQUEST_CODE_SELECT_CAR_SERIES);
                break;
            case R.id.ll_car_model:
                if (selectedCarSeries == null) {
                    SToast.show("请选择车系");
                    return;
                }
                Intent intent3 = new Intent(this, SelectCarInfoActivity.class);
                intent3.putExtra(Constants.CAR_BRAND_LEVEL_BRAND, 3);
                intent3.putExtra("pid", selectedCarSeries.getId());
                intent3.putExtra("Mark",mode_mark);
                startActivityForResult(intent3, REQUEST_CODE_SELECT_CAR_MODEL);
                break;
            case R.id.ll_vehicle_manufactory:
                if (selectedCarBrand == null) {
                    SToast.show("请选择车辆品牌");
                    return;
                }
                HashMap<String, String> params = new HashMap<>();
//                params.put("authkey", UserInfoManager.getInstance(MyApplication.getInstance()).getAuthKey());
//                params.put(ChannelInfoUtil.getCurrentChannelInfo().getCkey1().getYkey(), ChannelInfoUtil.getCurrentChannelInfo().getCkey1().getY7e_e73a691f02a46500201c3998e6a2989d());
                params.put("pid", selectedCarBrand.getId());
                params.put("level", "4");
                ApiClient.postForm(HttpConstants.GET_CAR_BRAND_LIST, params, new RespCallback<List<CarInfo.CarManufactory>>() {
                            @Override
                            protected void onRequestFailed(String msg) {
                                SToast.show(msg);
                            }

                            @Override
                            protected void onSuccess(List<CarInfo.CarManufactory> data) {

                                listPicker.setList(String.valueOf(R.id.ll_vehicle_manufactory), (ArrayList) data);
                                listPicker.listPickerDialog();
                            }

                            @Override
                            public void onBefore(Request request, int id) {
                                showDialog();
                            }

                            @Override
                            public void onAfter(int id) {
                                dismissDialog();
                            }

                        }
                );
                break;
            case R.id.ll_door_count:
                loadCarBasicInfo("door", R.id.ll_door_count);
                break;
            case R.id.ll_car_age:
                loadCarBasicInfo("cyear", R.id.ll_car_age);
                break;
            case R.id.ll_car_style:
                loadCarBasicInfo("bodystyle", R.id.ll_car_style);
                break;
            case R.id.ll_car_bsx:
                loadCarBasicInfo("trans", R.id.ll_car_bsx);
                break;
            case R.id.ll_car_pfbz:
                loadCarBasicInfo("emission", R.id.ll_car_pfbz);
                break;
            case R.id.ll_car_plunit:
                dataList.clear();
                dataList.add(new PickData("L", "L"));
                dataList.add(new PickData("T", "T"));
                listPicker.setList(String.valueOf(R.id.ll_car_plunit), dataList);
                listPicker.listPickerDialog();
                break;
            case R.id.ll_car_rllx:
                loadCarBasicInfo("fueltype", R.id.ll_car_rllx);
                break;
            case R.id.ll_car_qdfs:
                loadCarBasicInfo("drivetrain", R.id.ll_car_qdfs);
                break;
            case R.id.ll_car_gs:
                loadCarBasicInfo("cylinders", R.id.ll_car_gs);
                break;
            case R.id.ll_car_zws:
                loadCarBasicInfo("seats", R.id.ll_car_zws);
                break;
            case R.id.iv_chuchang:
                DatePickerUtil.show(this, this, true, "iv_chuchang");
                break;
            case R.id.iv_shangpai:
                DatePickerUtil.show(this, this, true, "iv_shangpai");
                break;
            case R.id.tv_query_username:
                Intent intent1 = new Intent(this, CarOwnerListActivity.class);
                intent1.putExtra("USER_NAME", etUserName.getText().toString());
                startActivityForResult(intent1, SELECT_OWNER_ARCHIVE_REQUEST_CODE);
                break;
            case R.id.tv_query_vin:
                if (TextUtils.isEmpty(etVin.getText().toString()) || etVin.getText().toString().length() != 17) {
                    SToast.show(R.string.please_enter_right_vin, Gravity.CENTER);
                    return;
                }
                loadCarInfoListByVin(etVin.getText().toString().toUpperCase());
                break;
            case R.id.tv_copy_vin:
                if (TextUtils.isEmpty(etVin.getText().toString()) || etVin.getText().toString().length() != 17) {
                    SToast.show(R.string.please_enter_right_vin, Gravity.CENTER);
                    return;
                }
                ClipboardManager cmb = (ClipboardManager)getSystemService(CLIPBOARD_SERVICE);
                cmb.setText(etVin.getText().toString());
                SToast.show("复制成功", Gravity.CENTER);
                break;
            case R.id.vRight:
                saveCarArchiveAction();
                break;
            case R.id.tv_save:
                saveCarArchiveAction();
                break;
            default:
                break;
        }

    }

    public void loadCarBasicInfo(final String car_item_code, final int idTag) {
        HashMap<String, String> params = new HashMap<>();
//        params.put("authkey", UserInfoManager.getInstance(MyApplication.getInstance()).getAuthKey());
//        params.put(ChannelInfoUtil.getCurrentChannelInfo().getCkey1().getYkey(), ChannelInfoUtil.getCurrentChannelInfo().getCkey1().getY7e_e73a691f02a46500201c3998e6a2989d());
        params.put("field", car_item_code);
        ApiClient.postForm(HttpConstants.GET_CAR_BASIC_INFO, params, new StringCallback() {
            @Override
            public void onError(Call call, Exception e, int id) {
                SToast.show("数据获取失败");
            }

            @Override
            public void onResponse(String response, int id) {
                try {
                    JSONObject jsonObject = new JSONObject(response).optJSONObject("data");
                    List<CarBaseInfoData> infoList = new Gson().fromJson(jsonObject.optString(car_item_code), new TypeToken<List<CarBaseInfoData>>() {
                    }.getType());
                    listPicker.setList(String.valueOf(idTag), (ArrayList) infoList);
                    listPicker.listPickerDialog();
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onBefore(Request request, int id) {
                showDialog();
            }

            @Override
            public void onAfter(int id) {
                dismissDialog();
            }
        });
    }


    //    根据Vin查询车辆档案
    private void loadCarInfoListByVin(String vin) {
        HashMap<String, String> params = new HashMap<>();
//        params.put("authkey", UserInfoManager.getInstance(MyApplication.getInstance()).getAuthKey());
//        params.put(ChannelInfoUtil.getCurrentChannelInfo().getCkey1().getYkey(), ChannelInfoUtil.getCurrentChannelInfo().getCkey1().getY7e_e73a691f02a46500201c3998e6a2989d());
        params.put("vin", vin);

        ApiClient.postForm(HttpConstants.GET_CAR_INFO_LIST_BY_VIN, params,
                new StringCallback() {

                    @Override
                    public void onError(Call call, Exception e, int id) {
                        if (e instanceof UnknownHostException || e instanceof SocketException) {
                            SToast.show(R.string.tip_network_error, Gravity.CENTER);
                            return;
                        }
                    }

                    @Override
                    public void onResponse(String response, int id) {
                        Log.e(TAG, "onResponse: Vin查询结果 ： " + response);
                        try {
                            JSONObject obj = new JSONObject(response);
                            if (null != obj && obj.optInt("code") == -30) {
                                showRemind(obj.optString("msg"));
                            } else if (null != obj && obj.optInt("code") == 1) {
                                List<CarInfoSearchedByVin> data = new Gson().fromJson(obj.getString("data"), new TypeToken<List<CarInfoSearchedByVin>>() {
                                }.getType());
                                if (null != data && data.size() != 0) {
                                    Intent intent = new Intent(AddCarArchiveActivity.this, ArchiveSelectCarActivity.class);
                                    intent.putExtra("list", (Serializable) data);
                                    Log.e(TAG, "onResponse: Data Size : =================== " + data.size() );
                                    startActivityForResult(intent, SELECT_CAR_BY_VIN_REQUEST_CODE);
                                } else {
                                    showRemind("查询无结果");
                                }
                            } else if (null != obj && obj.optInt("code") == 0) {
                                SToast.show(obj.optString("msg"));
                            }
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }

                    @Override
                    public void onBefore(Request request, int id) {
                        showDialog();
                    }

                    @Override
                    public void onAfter(int id) {
                        dismissDialog();
                    }

                }
        );
    }

    public void showRemind(String remindStr) {
        if (null == singleDialog) {
            singleDialog = new SDialog(this, R.string.t_message_title, remindStr, AddCarArchiveActivity.this, SDialog.TYPE_1_BTN);
        } else {
            singleDialog.setContent(remindStr);
        }
        singleDialog.show();
    }

    private void saveCarArchiveAction() {
        if (CURRENT_OPERATION_MODE == OPERATION_MODE_ADD_NEW_ARCHIVE_INFO) {
            if (verifyInputValid()) {
                addNewOrUpdateArchiveInfo(HttpConstants.INSERT_VEHICLE_INFO);
            }
        } else {
            if (verifyInputValid()) {
                addNewOrUpdateArchiveInfo(HttpConstants.GET_OR_UPDATE_CAR_ARCHIVE);
            }
        }
    }

    private boolean verifyInputValid() {
        if (TextUtils.isEmpty(etVin.getText().toString())) {
            SToast.show("请输入VIN");
            return false;
        }
        if (TextUtils.isEmpty(tvCarBrand.getText().toString())) {
            SToast.show("请选择车辆品牌");
            return false;
        }
        if (TextUtils.isEmpty(tvCarSeries.getText().toString())) {
            SToast.show("请选择车系");
            return false;
        }
//        if (TextUtils.isEmpty(tvCarModel.getText().toString())) {
//            SToast.show("请选择车型");
//            return false;
//        }
        if (TextUtils.isEmpty(tvCarAge.getText().toString())) {
            SToast.show("请选择车辆年式");
            return false;
        }
        if (TextUtils.isEmpty(tvChuchangDate.getText().toString())) {
            SToast.show("请选择出厂年月");
            return false;
        }
        if (TextUtils.isEmpty(tvShangpaiDate.getText().toString())) {
            SToast.show("请选择首次上牌日期");
            return false;
        }
        if (TextUtils.isEmpty(tvCarStyle.getText().toString())) {
            SToast.show("请选择车身样式");
            return false;
        }
        if (TextUtils.isEmpty(tvCarBsx.getText().toString())) {
            SToast.show("请选择变速箱");
            return false;
        }
        if (TextUtils.isEmpty(tvCarPfbz.getText().toString())) {
            SToast.show("请选择排放标准");
            return false;
        }
        if (TextUtils.isEmpty(etPlNumber.getText().toString())) {
            SToast.show("请输入排量");
            return false;
        }
        if (TextUtils.isEmpty(tvCarPl.getText().toString())) {
            SToast.show("请选择排量单位");
            return false;
        }
        if (TextUtils.isEmpty(tvCarRllx.getText().toString())) {
            SToast.show("请选择燃料类型");
            return false;
        }
        if (TextUtils.isEmpty(tvCarQdfs.getText().toString())) {
            SToast.show("请选择驱动方式");
            return false;
        }
        if (TextUtils.isEmpty(tvCarZws.getText().toString())) {
            SToast.show("请选择座位数");
            return false;
        }
        if (TextUtils.isEmpty(tvDoorCount.getText().toString())) {
            SToast.show("请选择车门数");
            return false;
        }
//        if (TextUtils.isEmpty(tvVehicleManufactory.getText().toString())) {
//            SToast.show("请选择生产厂家");
//            return false;
//        }
//        if (TimeUtils.string2Seconds(tvShangpaiDate.getText().toString()) < TimeUtils.string2Seconds(tvChuchangDate.getText().toString())) {
//            SToast.show("\"首次上牌日\"不能早于\"出厂年月\"");
//            return false;
//        }
        if (TextUtils.isEmpty(carInfoMap.get("ownercid"))) {
            SToast.show("请绑定客户信息");
            return false;
        }
        return true;
    }

    private void addNewOrUpdateArchiveInfo(String httpUrl) {
//        carInfoMap.put("authkey", UserInfoManager.getInstance(MyApplication.getInstance()).getAuthKey());
//        carInfoMap.put(ChannelInfoUtil.getCurrentChannelInfo().getCkey1().getYkey(), ChannelInfoUtil.getCurrentChannelInfo().getCkey1().getY7e_e73a691f02a46500201c3998e6a2989d());
        carInfoMap.put("channel", ChannelInfoUtil.getCurrentChannelInfo().getChannel());
        carInfoMap.put("vin", etVin.getText().toString().toUpperCase());
//        if (!TextUtils.isEmpty(etCarFdjgl.getText().toString())) {
//            carInfoMap.put("epower", etCarFdjgl.getText().toString());
//        }

        if (!TextUtils.isEmpty(tvShangpaiDate.getText().toString())) {
            carInfoMap.put("licdate", String.valueOf(TimeUtils.string2Seconds(tvShangpaiDate.getText().toString())));
        }
        if (!TextUtils.isEmpty(tvChuchangDate.getText().toString())) {
            carInfoMap.put("exwdate", String.valueOf(TimeUtils.string2Seconds(tvChuchangDate.getText().toString())));
        }
        if (!TextUtils.isEmpty(etPlateNumber.getText().toString())) {
            carInfoMap.put("plate", etPlateNumber.getText().toString());
        }
        if (!TextUtils.isEmpty(etEngineNumber.getText().toString())) {
            carInfoMap.put("engineno", etEngineNumber.getText().toString());
        }
        if (!TextUtils.isEmpty(etPlNumber.getText().toString())) {
            carInfoMap.put("displace", etPlNumber.getText().toString());
        }
        for (String key : carInfoMap.keySet()) {
            Log.e(TAG, "=========addNewOrUpdateArchiveInfo:  update Params : =======   key : " + key + "   Value :   " + carInfoMap.get(key));
        }
        ApiClient.postForm(httpUrl, carInfoMap, new StringCallback() {

                    @Override
                    public void onError(Call call, Exception e, int id) {
                        SToast.show("保存失败");
                    }

                    @Override
                    public void onResponse(String response, int id) {
                        try {
                            JSONObject result = new JSONObject(response);
                            if (result.optInt("code") == 1) {
                                if (CURRENT_OPERATION_MODE == OPERATION_MODE_ADD_NEW_ARCHIVE_INFO) {
                                    SToast.show("添加成功");
                                } else {
                                    SToast.show("修改成功");
                                }

                                carInfoMap.clear();
                                Intent intent = new Intent();
                                intent.putExtra("CREATE_ARCHIVE_OK", true);
                                setResult(RESULT_OK, intent);
                                MyApplication.getInstance().removeActivity(AddCarArchiveActivity.class);
                                finish();
                            } else {
                                SToast.show(result.optString("msg"));
                            }
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }

                    @Override
                    public void onBefore(Request request, int id) {
                        showDialog();
                    }

                    @Override
                    public void onAfter(int id) {
                        dismissDialog();
                    }

                }
        );

    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (null == data) {
            return;
        }
        switch (requestCode) {
            case SELECT_OWNER_ARCHIVE_REQUEST_CODE:
                if (resultCode == RESULT_OK) {
                    carOwnerArchiveInfo = (CustomerArchiveInfo) data.getSerializableExtra("USER_ARCHIVE");
                    carInfoMap.put("ownercid", carOwnerArchiveInfo.getCid());
                    etUserName.setText(carOwnerArchiveInfo.getRealname());
                    etUserTelenumber.setText(carOwnerArchiveInfo.getPhone());
                    etUserAddress.setText(carOwnerArchiveInfo.getAddress());
                    tvUserGender.setText(carOwnerArchiveInfo.getSex().equals("1") ? "男" : carOwnerArchiveInfo.getSex().equals("2") ? "女" : "未知");
                    tvUserCategory.setText(carOwnerArchiveInfo.getCategory().equals("1") ? "个人" :
                            carOwnerArchiveInfo.getCategory().equals("2") ? "公司" : carOwnerArchiveInfo.getCategory().equals("3") ? "行政单位" : "未知");
                }
                break;
            case SELECT_CAR_BY_VIN_REQUEST_CODE:
                if (resultCode == RESULT_OK) {
                    carInfoReturnedByVinSearch = (CarInfoSearchedByVin) data.getSerializableExtra("CAR_ARCHIVE");
                    getIdsFromOrderId(carInfoReturnedByVinSearch.getOrder_id());
                }
                break;
            case REQUEST_CODE_SELECT_CAR_BRAND:
                if (null != data.getSerializableExtra("CAR_BRAND")) {
                    selectedCarBrand = (CarInfo.CarBrand) data.getSerializableExtra("CAR_BRAND");
                    tvCarBrand.setText(selectedCarBrand.getTitle());
                    carInfoMap.put("brand", selectedCarBrand.getId());

                    clearSeries();
                    clearSpec();
                }
                break;
            case REQUEST_CODE_SELECT_CAR_SERIES:
                if (null != data.getSerializableExtra("CAR_SERIES")) {
                    selectedCarSeries = (CarInfo.CarSeries) data.getSerializableExtra("CAR_SERIES");
                    tvCarSeries.setText(selectedCarSeries.getTitle());
                    carInfoMap.put("series", selectedCarSeries.getId());

                    clearSpec();
                }
                break;
            case REQUEST_CODE_SELECT_CAR_MODEL:
                if (null != data.getSerializableExtra("CAR_MODEL")) {
                    selectedCarModel = (CarInfo.CarModel) data.getSerializableExtra("CAR_MODEL");
                    tvCarModel.setText(selectedCarModel.getTitle());
                    carInfoMap.put("spec", selectedCarModel.getId());
                }
                break;
            default:
                break;
        }
    }

    private void getIdsFromOrderId(String order_id) {
        HashMap<String, String> params = new HashMap<>();
//        params.put("authkey", UserInfoManager.getInstance(MyApplication.getInstance()).getAuthKey());
//        params.put(ChannelInfoUtil.getCurrentChannelInfo().getCkey1().getYkey(), ChannelInfoUtil.getCurrentChannelInfo().getCkey1().getY7e_e73a691f02a46500201c3998e6a2989d());
        params.put("order_id", order_id);

        Log.e(TAG, "getIdsFromOrderId:  order id : " + params);

        ApiClient.postForm(HttpConstants.GET_VEHICLE_DATA_FOR_ORDER_ID, params, new StringCallback() {

            @Override
            public void onError(Call call, Exception e, int id) {
                if (e instanceof UnknownHostException || e instanceof SocketException) {
                    SToast.show(R.string.tip_network_error, Gravity.CENTER);
                    return;
                }
            }

            @Override
            public void onResponse(String response, int id) {
                Log.e(TAG, "onResponse:  " + response);
                try {
                    String str = new JSONObject(response).optString("data");
                    Gson gson = new Gson();
                    CarBaseInfoIds data = gson.fromJson(str, CarBaseInfoIds.class);
                    if (null != data) {
                        carInfoMap.put("gdprice", data.getGdprice());

                        if (!TextUtils.isEmpty(data.getModel_name())){
                            ll_car_model_tip.setVisibility(View.VISIBLE);
                            tv_car_model_vv.setText(data.getModel_name());
                            mode_mark = data.getModel_name();
                        }

                        if (isValidFormat(data.getBrand())) {
                            tvCarBrand.setText(data.getBrand().split(",")[0]);
                            carInfoMap.put("brand", data.getBrand().split(",")[1]);
                            if (selectedCarBrand == null)
                                selectedCarBrand = new CarInfo.CarBrand(data.getBrand().split(",")[1], data.getBrand().split(",")[0], "");
                            else {
                                selectedCarBrand.setId(data.getBrand().split(",")[1]);
                                selectedCarBrand.setTitle(data.getBrand().split(",")[0]);
                            }
                        }

                        if (isValidFormat(data.getSeries())) {
                            tvCarSeries.setText(data.getSeries().split(",")[0]);
                            carInfoMap.put("series", data.getSeries().split(",")[1]);
                            if (selectedCarSeries == null)
                                selectedCarSeries = new CarInfo.CarSeries(data.getSeries().split(",")[1], data.getSeries().split(",")[0]);
                            else {
                                selectedCarSeries.setId(data.getSeries().split(",")[1]);
                                selectedCarSeries.setTitle(data.getSeries().split(",")[0]);
                            }
                        }

                        if (isValidFormat(data.getSpec())) {
                            tvCarModel.setText(data.getSpec().split(",")[0]);
                            carInfoMap.put("spec", data.getSpec().split(",")[1]);
                            if (selectedCarModel == null)
                                selectedCarModel = new CarInfo.CarModel(data.getSpec().split(",")[1], data.getSpec().split(",")[0]);
                            else {
                                selectedCarModel.setId(data.getSpec().split(",")[1]);
                                selectedCarModel.setTitle(data.getSpec().split(",")[0]);
                            }
                        }

                        if (isValidFormat(data.getCyear())) {
                            tvCarAge.setText(data.getCyear().split(",")[0]);
                            carInfoMap.put("cyear", data.getCyear().split(",")[1]);
                        }

                        if (isValidFormat(data.getBodystyle())) {
                            tvCarStyle.setText(data.getBodystyle().split(",")[0]);
                            carInfoMap.put("bodystyle", data.getBodystyle().split(",")[1]);
                        }

                        if (isValidFormat(data.getTrans())) {
                            tvCarBsx.setText(data.getTrans().split(",")[0]);
                            carInfoMap.put("trans", data.getTrans().split(",")[1]);
                        }

                        if (isValidFormat(data.getEmission())) {
                            tvCarPfbz.setText(data.getEmission().split(",")[0]);
                            carInfoMap.put("emission", data.getEmission().split(",")[1]);
                        }

                        if (isValidFormat(data.getFueltype())) {
                            tvCarRllx.setText(data.getFueltype().split(",")[0]);
                            carInfoMap.put("fueltype", data.getFueltype().split(",")[1]);
                        }

                        if (isValidFormat(data.getDrivetrain())) {
                            tvCarQdfs.setText(data.getDrivetrain().split(",")[0]);
                            carInfoMap.put("drivetrain", data.getDrivetrain().split(",")[1]);
                        }

                        if (isValidFormat(data.getCylinders())) {
                            tvCarGs.setText(data.getCylinders().split(",")[0]);
                            carInfoMap.put("cylinders", data.getCylinders().split(",")[1]);
                        }

                        if (isValidFormat(data.getSeats())) {
                            tvCarZws.setText(data.getSeats().split(",")[0]);
                            carInfoMap.put("seats", data.getSeats().split(",")[1]);
                        }

                        if (isValidFormat(data.getDoor())) {
                            tvDoorCount.setText(data.getDoor().split(",")[0]);
                            carInfoMap.put("door", data.getDoor().split(",")[1]);
                        }

                        if (isValidFormat(data.getFacturer())) {
                            tvVehicleManufactory.setText(data.getFacturer().split(",")[0]);
                            carInfoMap.put("facturer", data.getFacturer().split(",")[1]);
                        }

                        if (!TextUtils.isEmpty(data.getDisplace())) {
                            etPlNumber.setText(data.getDisplace());
                            carInfoMap.put("displace", data.getDisplace());
                        }

                        if (!TextUtils.isEmpty(data.getDispunit())) {
                            tvCarPl.setText(data.getDispunit());
                            carInfoMap.put("dispunit", data.getDispunit());
                        }
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onBefore(Request request, int id) {
                showDialog();
            }

            @Override
            public void onAfter(int id) {
                dismissDialog();
            }

        });

    }

    /**
     * WheelView控件选择按钮点击的回调
     *
     * @param tag      用于标志view的tag
     * @param infoData 选中的数据项
     */
    @Override
    public void onListOK(String tag, InfoData infoData) {
        switch (tag) {
            case R.id.ll_car_brand + "":
                tvCarBrand.setText(infoData.getTitle());
                if (infoData instanceof CarInfo.CarBrand) {
                    selectedCarBrand = (CarInfo.CarBrand) infoData;
                }
                carInfoMap.put("brand", infoData.getId());
                clearSeries();
                clearSpec();
                break;
            case R.id.ll_car_series + "":
                tvCarSeries.setText(infoData.getTitle());

                if (infoData instanceof CarInfo.CarSeries) {
                    selectedCarSeries = (CarInfo.CarSeries) infoData;
                }

                carInfoMap.put("series", infoData.getId());
                clearSpec();
                break;
            case R.id.ll_car_model + "":
                tvCarModel.setText(infoData.getTitle());
                if (infoData instanceof CarInfo.CarModel) {
                    selectedCarModel = (CarInfo.CarModel) infoData;
                }
                carInfoMap.put("spec", infoData.getId());
                break;
            case R.id.ll_door_count + "":
                tvDoorCount.setText(infoData.getTitle());
                carInfoMap.put("door", infoData.getId());
                break;
            case R.id.ll_vehicle_manufactory + "":
                if (infoData instanceof CarInfo.CarManufactory) {
                    selectedManufactory = (CarInfo.CarManufactory) infoData;
                    tvVehicleManufactory.setText(infoData.getTitle());
                    carInfoMap.put("facturer", infoData.getId());
                }
                break;
            case R.id.ll_car_age + "":
                tvCarAge.setText(infoData.getTitle());
                carInfoMap.put("cyear", infoData.getId());
                break;
            case R.id.ll_car_style + "":
                tvCarStyle.setText(infoData.getTitle());
                carInfoMap.put("bodystyle", infoData.getId());
                break;
            case R.id.ll_car_bsx + "":
                tvCarBsx.setText(infoData.getTitle());
                carInfoMap.put("trans", infoData.getId());
                break;
            case R.id.ll_car_pfbz + "":
                tvCarPfbz.setText(infoData.getTitle());
                carInfoMap.put("emission", infoData.getId());
                break;
            case R.id.ll_car_plunit + "":
                tvCarPl.setText(infoData.getTitle());
                Log.e(TAG, "onListOK: dispunit : " + infoData.getId() + "   title :  " + infoData.getTitle());
//               排量单位
                carInfoMap.put("dispunit", infoData.getTitle());
                break;
            case R.id.ll_car_rllx + "":
                tvCarRllx.setText(infoData.getTitle());
//              燃料类型
                carInfoMap.put("fueltype", infoData.getId());
                break;
            case R.id.ll_car_qdfs + "":
                tvCarQdfs.setText(infoData.getTitle());
                carInfoMap.put("drivetrain", infoData.getId());
                break;
            case R.id.ll_car_gs + "":
                tvCarGs.setText(infoData.getTitle());
                carInfoMap.put("cylinders", infoData.getId());
                break;
            case R.id.ll_car_zws + "":
                tvCarZws.setText(infoData.getTitle());
                carInfoMap.put("seats", infoData.getId());
                break;
            default:
                break;
        }
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        DatePickerUtil.clearPicker();
    }

    @Override
    public void onBackPressed() {
        if (listPicker.isListPickerShowing() && listPicker.getPopupWindow() != null)
            listPicker.hidePop(listPicker.getPopupWindow());
        else
            super.onBackPressed();
    }


    @Override
    public void onDatePicked(String year, String monthOfYear, String dayOfMonth) {
        switch (DatePickerUtil.getTag()) {
            case "iv_chuchang":
                tvChuchangDate.setText(new StringBuilder().append(year).append("-").append((monthOfYear)).append("-").append(dayOfMonth).toString());
                break;
            case "iv_shangpai":
                tvShangpaiDate.setText(new StringBuilder().append(year).append("-").append((monthOfYear)).append("-").append(dayOfMonth).toString());
                break;
            default:
                break;
        }
    }

    @Override
    public void onClick(boolean l, View view) {

    }

    public void clearSeries(){
        selectedCarSeries = null;
        tvCarSeries.setText("");
        carInfoMap.put("series", "");
    }

    public void clearSpec(){
        selectedCarModel = null;
        tvCarModel.setText("");
        carInfoMap.put("spec", "");
    }
}
